/*	$Id: if_myrinet.c 6 2008-07-29 02:30:10Z phrakt $	*/
/*
 * Copyright (c) 2003 Jean-Francois Brousseau <jfb@openbsd.org>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHMYRINET IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * Myrinet emulation
 * =================
 *
 * Myrinet is a high-performance low-latency interface type originally
 * created by Myricom, although it is now an ANSI standard (ANSI/VITA 26-1998)
 * and all of the specifications are open for implementation.
 *
 * Header
 * ------
 *
 * The header part of a Myrinet packet is composed of a variable-length source
 * route (see routing).
 *
 * Routing
 * -------
 *
 * Myrinet performs routing by using source route bytes at the head of
 * packets.  The header of each packet must start with a sequence of bytes
 * describing the source route of the packet.  Each route byte specifies a
 * differential between the source and destination port, thereby allowing
 * reverse routing to be performed by simply inversing the signs.  Each
 * route byte must have MSB set to 1.
 *
 * A switch which receives a packet whose first byte does not have the MSB
 * set to 1 will discard the packet.
 * A host receiving a Myrinet packet should see no route bytes at the start
 * of the packet, as they have been stripped by the switches during routing.
 *
 * Checksum
 * --------
 *
 * Each Myrinet packet is terminated by a 1-byte CRC similar to the ATM CRC.
 * The byte is calculated from all of the packet's data, including the header
 * portion, using the following polynomial:
 *
 *	X^8 + X^2 + X + 1
 *
 *
 * http://www.myri.com/scs/types.html
 */

#include <sys/param.h>
#include <sys/stat.h>
#include <sys/ioctl.h>

#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>

#include "if.h"
#include "dlink.h"
#include "pforge.h"


#define PFIF_MYRINET_TYPELEN       2     /* Myrinet packet type length */
#define PFIF_MYRINET_CRCLEN        1     /* Cyclic Redundancy Check length */
#define PFIF_MYRINET_MINFRMLEN    64     /* minimum frame length */
#define PFIF_MYRINET_MAXFRMLEN  1518     /* max frame length */

/*
 * Myrinet hardware does not have the concept of MTU, so the specification
 * states that any given MTU should be handled by the software and should be
 * of at least 4MB.
 */
#define PFIF_MYRINET_MAXMTU        0
#define PFIF_MYRINET_MINMTU       (4 * 1024 * 1024)

#define PFIF_MYRINET_ADDRFMT   "%02x:%02x:%02x:%02x:%02x:%02x"


/* Myrinet packet types */
#define PFIF_MYRITYPE_RESERVED     0x0000	/* Reserved: hardware safety */
#define PFIF_MYRITYPE_MYRIMAP      0x0005
#define PFIF_MYRITYPE_MYRIPROBE    0x0006
#define PFIF_MYRITYPE_MYRIOPT      0x0007
#define PFIF_MYRITYPE_GM           0x0008
#define PFIF_MYRITYPE_GM1MAP       0x000f
#define PFIF_MYRITYPE_LINKTEST     0x0010
/* 0x0011 to 0x001f reserved */
#define PFIF_MYRITYPE_GM1ETHEMUL   0x0020	/* GM-1 Ethernet emulation */
#define PFIF_MYRITYPE_SSNMCAST     0x0110	/* SSN Multicasting */
#define PFIF_MYRITYPE_PACKETWAY    0x0300	/* PacketWay protocol */
#define PFIF_MYRITYPE_ITB          0x0320	/* ITB */
#define PFIF_MYRITYPE_CSPI         0x0330	/* CSPI */
#define PFIF_MYRITYPE_MPI          0x0340	/* MPI */
#define PFIF_MYRITYPE_BIP          0x0350	/* BIP */
#define PFIF_MYRITYPE_CLF          0x0370	/* CLF */



int   pf_myri_init    (void);
void  pf_myri_fini    (void);
int   pf_myri_input   (PF_NETIF *, PF_PKT *);
int   pf_myri_output  (PF_NETIF *, PF_PKT *);
void  pf_myri_print   (PF_NETIF *, PF_PKT *);
int   pf_myri_crc     (PF_PKT *);





struct pf_myri_hdr {
};


struct pf_netif_myri {
};



struct pf_netif_ops pf_myri_ops = {
	pf_myri_init,
	pf_myri_fini,
	NULL,
	NULL,
	pf_myri_input,
	pf_myri_output,
	NULL,
	pf_myri_print
};


/*
 * pf_myri_init()
 *
 * Initialization routine for the Ethernet
 */

int
pf_myri_init(void)
{
	return (0);
}


/*
 * pf_myri_fini()
 *
 */

void
pf_myri_fini(void)
{

}


/*
 * pf_myri_input()
 *
 * Input routine to read Ethernet frames and decapsulate the Ethernet layer.
 */

int
pf_myri_input(PF_NETIF *ifp, PF_PKT *pkt)
{
	int ret;
	struct pf_myri_hdr *hdr;

	pf_myri_print(ifp, pkt);
}


/*
 * pf_myri_output()
 *
 */

int
pf_myri_output(PF_NETIF *ifp, PF_PKT *pkt)
{
	uint8_t bigbuf[2048];
	struct pf_myri_hdr *hdr;

}


/*
 * pf_myri_print()
 *
 * Print a human-readable version of the data contained in an Ethernet header.
 */

void
pf_myri_print(PF_NETIF *ifp, PF_PKT *pkt)
{
	struct pf_myri_hdr *hdr;


}


/*
 * pf_myri_crc()
 *
 * Calculate the Cyclic Redundancy Checksum of the Myrinet packet <pkt>.
 * The Myrinet CRC is given by the following polynomial:
 *
 *	X^8 + X^2 + X + 1
 */
int
pf_myri_crc(PF_PKT *pkt)
{
	uint8_t crc, b;

	crc = 0;

	for (;;) {
	}


}
